package main

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"worklog/models"
)

var (
	username = "linan"
	password = "Linan@2002"
	protocol = "tcp"
	address  = "192.168.26.188"
	port     = "3306"
	dbname   = "worklog"
)

func main() {
	line := fmt.Sprintf("%s:%s@%s(%s:%s)/%s", username, password, protocol, address, port, dbname)
	fmt.Println(line)
	db, err := gorm.Open(mysql.Open("root:Linan@2002@tcp(192.168.26.188:3306)/worklog?charset=utf8mb4"), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}
	err = db.AutoMigrate(&models.User{})
	if err != nil {
		panic(err)
	}
	err = db.AutoMigrate(&models.Message{})
	if err != nil {
		panic(err)
	}
	//us := models.User{}
	//us.UserName = "这是我的第一个用户"
	//msg := models.Message{}
	//msg.UserName = us.UserName
	//msg.WorkContent = "这是工作内容"
	//db.Create(&msg)
	//db.Create(&us)

	//utils.MD5(models.User{}.PassWord)
}
